/*
 * Copyright (c) 2016 For Intelligent Group
 */
package com.intelligent.ispc.client.core.view.analysis.grr.render;

import com.intelligent.ispc.client.core.modal.SearchCsvTableModel;
import com.intelligent.ispc.client.utils.Colur;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * Created by cherry on 16/9/22.
 */
public class FileTableCellRenderer extends JRadioButton implements TableCellRenderer {
    private SearchCsvTableModel tableModel;

    /**
     * file table cell renderer constructor
     *
     * @param table table need to add render
     */
    public FileTableCellRenderer(JTable table) {
        super();
        tableModel = (SearchCsvTableModel) table.getModel();
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        int rowIndex = table.convertRowIndexToModel(row);
        if (tableModel.getData().get(rowIndex).isCheck()) {
            this.setSelected(true);
        } else {
            this.setSelected(false);
        }

        this.setBackground(Colur.WHITE);
        this.setHorizontalAlignment(CENTER);
        return this;
    }
}
